package com.example.biye;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.CompoundButton;
import android.widget.Toast;

public class GerenziliaoActivity extends AppCompatActivity {
    private SharedPreferences baocunShared;
    private EditText test_xingming;
    private EditText test_xingbie;
    private EditText test_nianling;
    private EditText test_shengao;
    private EditText test_tizhong;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gerenziliao);
        getSupportActionBar().hide();
        baocunShared = getSharedPreferences("share_baocun", MODE_PRIVATE);
        test_xingming = (EditText) findViewById(R.id.test_xingming);
        test_xingbie = (EditText) findViewById(R.id.test_xingbie);
        test_nianling = (EditText) findViewById(R.id.test_nianling);
        test_shengao = (EditText) findViewById(R.id.test_shengao);
        test_tizhong = (EditText) findViewById(R.id.test_tizhong);
        String xingming = baocunShared.getString("xingming", "");
        String xingbie = baocunShared.getString("xingbie", "");
        String nianling = baocunShared.getString("nianling", "");
        String shengao = baocunShared.getString("shengao", "");
        String tizhong = baocunShared.getString("tizhong", "");
        test_xingming.setText(xingming);
        test_xingbie.setText(xingbie);
        test_nianling.setText(nianling);
        test_shengao.setText(shengao);
        test_tizhong.setText(tizhong);
        Button buttonziliaobaocun = (Button) findViewById(R.id.buttonziliaobaocun);
        buttonziliaobaocun.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(test_xingming.length() == 0 || test_xingbie.length() == 0||test_nianling.length() == 0
                                ||test_shengao.length() == 0 || test_tizhong.length() == 0){
                            Toast.makeText(GerenziliaoActivity.this, "请完善信息", Toast.LENGTH_SHORT).show();
                        }
                        else {
                            SharedPreferences.Editor editor = baocunShared.edit();
                            editor.putString("xingming", test_xingming.getText().toString());
                            editor.putString("xingbie", test_xingbie.getText().toString());
                            editor.putString("nianling", test_nianling.getText().toString());
                            editor.putString("shengao", test_shengao.getText().toString());
                            editor.putString("tizhong", test_tizhong.getText().toString());
                            editor.commit();
                            Toast.makeText(GerenziliaoActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
        );
    }
}